{extend name="../../admin/view/public/system"}

{block name='title'}编辑员工权限-系统管理-{$account['name']}{/block}

{block name='content'}

<style>
    #xiangqing{
        color:#44abf7;
        font-size:14px;
    }
</style>
<div class="page-header">
    <span>当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}员工 <small>{if !empty($item['id'])}修改【{$item['username']}】{/if}</small></span></span>
</div>
<div class="page-content">
    <div class="page-sub-toolbar">
        <span class=''>
            <a class="btn btn-primary btn-sm" href="{:webUrl('perm/userPost')}">添加新员工</a>
            <a class="btn btn-default btn-sm" href="{:webUrl('perm/role')}">&nbsp;&nbsp;角色管理&nbsp;&nbsp;</a>
        </span>
    </div>
    <form id="dataform" action="" method="post" class="form-horizontal form-validate" >
        <input type="hidden" name="id" value="{$item['id']}" />

        <div class="form-group">
            <label class="col-lg control-label must">账号名称</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" name="username" class="form-control" value="{$item['username']}" {if !empty($item)}readonly{/if} data-rule-required=true autocomplete="off" />
                <span class='help-block'>不能输入 系统现有用户!  只能新增 权限才能生效. 新增的从这里可以修改</span>
                <!--<div class='form-control-static'>{$item['username']}</div>-->
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">员工密码</label>
            <div class="col-sm-9 col-xs-12">
                <a id="xiangqing" class="a" style="cursor:pointer">修改</a>
                <input type="hidden" id="mima" name="password" class="form-control" value="" autocomplete="off" {if empty($item['password'])}data-rule-required='false' {/if}  />
                <p>密码不填写则不修改</p>
                <!--<div class='form-control-static'>********</div>-->
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">所属角色</label>
            <div class="col-sm-9 col-xs-12">
                <input type='hidden' id='userid' name='roleid' value="{$role['id']}" />
                <div class='input-group'>
                    <input type="text" name="user" maxlength="30" value="{$role['rolename']}" id="user" class="form-control" readonly />
                    <div class='input-group-btn'>
                        <button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus1').modal();">选择角色</button>
                        <button class="btn btn-danger" type="button" onclick="$('#userid').val('');$('#user').val('');">清除选择</button>
                    </div>
                </div>
                <span class='help-block'>如果您选择了角色，则此用户本身就继承了此角色的所有权限</span>
                <div id="modal-module-menus1"  class="modal fade" tabindex="-1">
                    <div class="modal-dialog" style='width: 920px;'>
                        <div class="modal-content">
                            <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择角色</h3></div>
                            <div class="modal-body" style="padding:30px;">
                                <div class="row">
                                    <div class="input-group">
                                        <input type="text" class="form-control" name="keyword" value="" id="search-kwd1" placeholder="请输入角色名称" />
                                        <span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_users();">搜索</button></span>
                                    </div>
                                </div>
                                <div id="module-menus1" style="padding-top:5px;"></div>
                            </div>
                            <div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
                        </div>

                    </div>
                </div>
                <!--<div class='form-control-static'>{$user['username']}</div>-->
            </div>
        </div>

<!--        <div class="form-group">-->
<!--            <label class="col-lg control-label">绑定微信号</label>-->
<!--            <div class="col-sm-9 col-xs-12">-->
<!--                {:tpl_selector('wxapp_openid',array('key'=>'wxapp_openid','text'=>'nickname', 'thumb'=>'avatar','multi'=>0,'placeholder'=>'昵称','buttontext'=>'选择用户', 'items'=>$member,'url'=>webUrl('web.member.index/query') ))}-->
<!--                <div class="form-control-static">提示: 员工绑定微信号后，使用手机端时可以直接授权登录</div>-->
<!--            </div>-->
<!--        </div>-->

        <div class="form-group">
            <label class="col-lg control-label">员工姓名</label>
            <div class="col-sm-9  col-xs-12">
                <input type="text" name="realname" class="form-control" value="{$item['realname']}" />
                <!--<div class='form-control-static'>{$item['realname']}</div>-->
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">员工电话</label>
            <div class="col-sm-9  col-xs-12">
                <input type="text" name="mobile" class="form-control" value="{$item['mobile']}" />
                <!--<div class='form-control-static'>{$item['mobile']}</div>-->
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">员工状态</label>
            <div class="col-sm-9  col-xs-12">
                <label class='radio-inline'>
                    <input type='radio' name='status' value='1' {if $item['status']==1}checked{/if} /> 启用
                </label>
                <label class='radio-inline'>
                    <input type='radio' name='status' value='0' {if $item['status']==0}checked{/if} /> 禁用
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">关联会员</label>
            <div class="col-sm-9  col-xs-12">
                {:tpl_selector('mid',array('key' => 'id','text'=>'realname1','value'=>$item['realname1'],'thumb' => 'avatar','preview'=>true,'readonly'=>true,'multi'=>0, 'required'=>false,'placeholder'=>'请选择用户信息','buttontext'=>'选择用户', 'items'=>$memberInfo,'url'=>webUrl('perm/memberQuery')))}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">截止时间</label>
            <div class="col-sm-6 col-xs-12">
                <div class="input-group">
                    {:tpl_form_field_date('end_time',$item['end_time'],true)}
                    <span class="input-group-addon">
                        <label class="radio-inline" style="margin-top:-9px;">
                            <input type="radio" name="limit_time" value="1" {if $item['end_time'] > 0}checked="checked"{/if}> 限制时间
                        </label>
                        <label class="radio-inline" style="margin-top:-9px;">
                            <input type="radio" name="limit_time" value="0" {if $item['end_time'] <= 0}checked="checked"{/if}> 不限时间
                        </label>
                    </span>
                </div>
            </div>
        </div>

        {include file="perm/perms" /}

        <div class="form-group"></div>
        <div class="form-group">
            <label class="col-lg control-label"></label>
            <div class="col-sm-9 col-xs-12">
                <input type="hidden" name="uid" value="{$item['uid']}" />
                <input type="submit" value="提交" class="btn btn-primary" />
                <a type="button" href="{:webUrl('perm/user',['module' => $_GET['module']])}" style='margin-left:10px;' class="btn btn-default" >返回列表</a>
            </div>
        </div>

    </form>
</div>

<script language='javascript'>
    $('#xiangqing').click(function(){
        $('#xiangqing').attr("class","hidden");
        $('#mima').attr("type","password");
    })

    function search_users() {
        $("#module-menus1").html("正在搜索....");
        $.get('{:webUrl("perm/roleQuery")}', {
            keyword: $.trim($('#search-kwd1').val())
        }, function(dat){
            $('#module-menus1').html(dat);
        });
    }

    function select_role(o) {
        $("#userid").val(o.id);
        $("#user").val( o.rolename );
        console.log(o)
        let perms = o.perms.split(',');
        $(':checkbox').removeAttr('disabled').removeAttr('checked').each(function(){

            var _this = $(this);
            var perm = '';
            if( _this.data('group') ){
                perm+=_this.data('group');
            }
            if( _this.data('parent') ){
                if (_this.data('parent') != 'text') {
                    perm += "." + _this.data('parent');
                }
            }
            if( _this.data('son') ){
                if (_this.data('son') != 'text') {
                    perm += "." + _this.data('son');
                }
            }
            if( _this.data('grandson') ){
                if (_this.data('grandson') != 'text') {
                    perm += "." + _this.data('grandson');
                }
            }
            if( $.arrayIndexOf(perms,perm)!=-1){
                $(this).attr('disabled',true).get(0).checked =true;
            }

        });

        $(".close").click();
    }
</script>

{/block}